/*
 *  Speaker.cpp
 *  project8
 *
 *  Created by Luca Gobbo on 21-06-10.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#include "Speaker.h"
#include "string.h"

Speaker::Speaker(void){
	mkt_pin_configure (BOARD_PIN_SPEAKER, mkt_output);
}
Speaker::~Speaker(){}



void Speaker::switchOn(int h, int ms){
	
	double hCopy = h * 1.0;
	double msCopy = ms * 1.0;
	int vertraging = (int)((5.0 / hCopy) * 100000);
	int pulsen = (int)(h * (msCopy / 1000));
	
	char b1[10];
	int_to_char(vertraging,b1);
	
	char b2[10];
	int_to_char(pulsen,b2);
	
	for(int i = 0; i < pulsen; i++) {
		this->high();
		mkt_busy_wait_us(vertraging);
		this->low();
		mkt_busy_wait_us(vertraging);		
	}	
	
}

void Speaker::low(void){
	mkt_pin_write (BOARD_PIN_SPEAKER, 0);
}


void Speaker::high(void){
	mkt_pin_write (BOARD_PIN_SPEAKER, 1);
}





